<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="javax.jdo.Query" %>
<%@ page import="java.util.List" %>
<%@ page import="member.*" %>
<%@ page import="pk1.*" %>
<%@ page import="shared.PMF"  %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>
<style>

    /* START - toptop menu */

ul#TTPM

{

    list-style: none;

    float: left;

    margin:0px;

    padding:0px;

}



ul#TTPM li ul {

    display: none;

}

ul#TTPM li

{

    list-style: none;

    font-weight:bold;

}

ul#TTPM li:hover > ul {

    display: block;

    position:absolute;

    z-index:500;

    padding:0px;

} 

/* END - toptop menu */

    </style>
<style type="text/css">
.title {
	font-size: 70px;
	font-weight: bolder;
	color: #000;
}

.acc {
	color: #900;
	text-decoration: none;
}

.tablein {
	font-size: 36px;
	color: #CCC;
	background-color: #000;
}

.tableins {
	font-size: 36px;
	color: #CCC;
	background-color: #000;
	color: #CC3333;
}



.tabletit {
	font-size: 36px;
	color: #000;
	border-top-color: #000;
	border-right-color: #000;
	border-bottom-color: #000;
	border-left-color: #000;
	text-decoration: none;
	text-align: center;
}
a {text-decoration: none;
	 color: #000;
} 
body {
	background-color: #99C;
}
.tblCon {
	font-size: 16px;
	font-weight: bold;
	color: #000;
	text-decoration: none;
	text-align: center;
}

.inv {
	font-size: 24px;
	color: #FC0;
	text-decoration: none;
}


.tabletits {
	font-size: 36px;
	color: #FFFFFF;
	border-top-color: #000;
	border-right-color: #000;
	border-bottom-color: #000;
	border-left-color: #000;
	text-decoration: none;
	text-align: center;
}
</style></head>

<body>
<table width="1038" height="614" border="0" align="center">
  <tr>
    <th height="188" colspan="7" rowspan="2" class="title" scope="col">會員管理</th>
    <th width="208" height="128" scope="col">
    <%
	UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    String userName = "";
    boolean intiLogin = true;
    if (user != null) {
	    	userName = user.getNickname();
	    %>
	    <p>您目前是以 <u><%= userName %></u>登入<br>
	        如果這不是您的帳號</p>
	    <p>您可以<u><a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">登出</a></u>，再重新登入！</p>
		<p><u><a href="/mem/editMem01.jsp"><span class="tabletx">修改會員資料</span></a></u></p>
		<%
		//if是管理員印出管理頁面的圖示
	    PersistenceManager pm = PMF.get().getPersistenceManager();
		Query query = pm.newQuery(Member.class);
		query.setFilter("transTimes >= 0");
		try {
		    List<Member> results = (List<Member>) query.execute(userName);
		    if (!results.isEmpty()) {
		    	for (Member p : results) {
		    		if(userName.equals(p.getName())){
		    			if(p.getRequirement() == true){
			    			%>
			    		    <div id="apDiv1"><a href="admminpg.jsp"><img src="../adminIcon.png" width="87" height="105" /></a></div></th>
			    		    <%
			    		    break;
			    		}
					}
		    	}
		    } else {
		    	out.println("無會員資料!");
		    }
		} finally {
		    query.closeAll();
		    pm.close();
		}		
	
    } else {
    	%>
    		<p>請
    		<a href="<%= userService.createLoginURL(request.getRequestURI()) %>">登入</a>,
    		以便開始點數交換</p>
    	<%
        }
	
    //END
    %>
    </th>
  </tr>
  <tr>
    <td><p><a href="index_un.jsp" class="accept">回首頁</a></p></td>
  </tr>
  <tr>
    <th height="21" colspan="7" scope="row">&nbsp;</th>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <th height="133" colspan="2" bgcolor="#0066FF" class="tabletit" scope="row">
    <ul id="TTPM">

        <li id="TTPMI">我的活動

            <ul>

                <li><a href="StrtPg.jsp" ><span class="tablein">發起</span></a></li>

                <li><a href="Attend.jsp" ><span class="tablein">參與</span></a></li>


            </ul>

        </li>

    </ul></th>
    <th width="224" bgcolor="#CC66CC" scope="row"><a href="record.jsp" class="tabletit" >交易紀錄</a></th>
    <th colspan="3" bgcolor="#FFFF33" scope="row"><a href="MyInv.jsp" class="tabletits">我的邀請</a></th>
    <th width="202" bgcolor="#CC3333" class=" scope="row"><a href="mesg.jsp" class="tabletit">留言</a></th>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <th height="21" colspan="8" bgcolor="#000000" scope="row">&nbsp;</th>
  </tr>
  <%
		
		PersistenceManager pm2 = PMF.get().getPersistenceManager();
		Query query2 = pm2.newQuery(Invite.class);
		try {
				List<Invite> results = (List<Invite>) query2.execute();
			
	%>
<form method="get" action="/RecordServlet" >
<div id="content">
<div class="content_item">
<tr>
  <th height="53" colspan="3" bgcolor="#993300" class="tblCon" scope="row"><span class="inv">邀請我</span></th>
  <th height="53" colspan="4" class="tblCon" scope="row"><a href="MyInv.jsp" class="inv">我邀請</a></th>
  </tr>
<tr>
			<td>受邀者</td>
			<td>邀請者</td>
			<td>活動名稱</td>
			<td>受邀者交換條件</td>
			<td>邀請者交換條件</td>
			<td>日期</td>
			<td>留言</td>
			<td>狀態</td>
		</tr>
		<%
		
			for (Invite inv : results) {
				if (inv.checkInviterdID(userName)){
		%>
        
		<tr>
            <td><input type = "hidden" name = "inviterd_ID" value="<%=inv.getInviterdID()%>"/><%=inv.getInviterdID()%></td>
			<td><input type = "hidden" name = "inviter_ID" value="<%=inv.getInviterID()%>" /><%=inv.getInviterID()%></td>
			<td><input type = "hidden" name = "invite_activity" value="<%=inv.getInviteActivity()%>" /><%=inv.getInviteActivity()%></td>
			<td><input type = "hidden" name = "inviterd_con" value="<%=inv.getInviterdCon()%>" /><%=inv.getInviterdCon()%></td>
			<td><input type = "hidden" name = "inviter_con" value="<%=inv.getInviterCon()%>" /><%=inv.getInviterCon()%></td>
			<td><input type = "hidden" name = "invite_date" value="<%=inv.getInviteDate()%>" /><%=inv.getInviteDate()%></td>
			<td><input type = "hidden" name ="invite_message" value="<%=inv.getInviteMessage()%>" /><%=inv.getInviteMessage()%></td>
			<td>
              <label>
                <input type="submit" name="check1"  value="接受" />
                <input type="submit" name="check2"  value="不接受" />
              </label>         
            </td>
		</tr>
       
		<%
		
			}//if
				}// for
					
				} finally {
					query2.closeAll();
					pm2.close();
				}
			%>
</div></div>
</form>
</table>

</body>
</html>
